package Stack;

import java.util.Arrays;

public class MyStack {
    public int[]elem;
    public int useSize;

    public MyStack(){
        this.elem=new int[10];
    }

    public void push(int val){
        if(isFull()){
            this.elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[useSize++]=val;
    }

    public boolean isFull(){
        return useSize==elem.length;
    }

    public int pop(){
        if(isFull()){
            throw new EmptyStackException();
        }
       int i=elem[useSize-1];
       useSize--;
       return i;
    }
    //获取栈顶元素但是不删除
    public int peek(){
        if(isFull()){
            throw new EmptyStackException();
        }
        int i=elem[useSize-1];
        return i;
        }
    }

